#ifndef INC_ACCEPTOR_H
#define INC_ACCEPTOR_H

#include "../base/Observable.h"

#include <memory>
#include <stack>
#include <boost/shared_ptr.hpp>

class Command;

class Acceptor : public Observable
{
	typedef boost::shared_ptr<Command> CommandPtr;

	public:
		Acceptor();

		/**
		 * Takes ownership of cmd and executes it. If the last accept was
		 * transitive (see acceptTransitive), cmd will be unexecuted first, as
		 * the caller must provide the same command.
		 */
		void accept(std::auto_ptr<Command> cmd);

		/**
		 * Executes the command but does not store it. This is to support
		 * transitive operations that should be considered as one for undo.
		 *
		 * The caller _must_ provide the same command to accept() when finished
		 * with the transitive operation.
		 */
		void acceptTransitive(Command& cmd);

		bool canUndo() const;
		void undo();
		bool canRedo() const;
		void redo();

	private:

		std::stack<CommandPtr> _undo;
		std::stack<CommandPtr> _redo;
};

#endif // INC_ACCEPTOR_H

